package com.bocai.kelalacar.ui.car.set.ada;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bocai.kelalacar.R;
import com.bocai.kelalacar.base.BaseRecyclerAdapter;
import com.bocai.kelalacar.base.BaseRecyclerViewHolder;
import com.bocai.kelalacar.bean.ApplyWayBean;
import com.bocai.kelalacar.ui.car.set.presenter.WithdrawTypePresenter;
import com.bocai.kelalacar.widget.AlertDialog;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by yuanfei on 2017/6/22.
 */

public class UnionPayAda extends BaseRecyclerAdapter<ApplyWayBean.BankCardBean> {


    private boolean isShow;

    WithdrawTypePresenter presenter;

    public void setPresenter(WithdrawTypePresenter presenter){
        this.presenter = presenter;
    }

    @Override
    public void showData(BaseRecyclerViewHolder viewHolder, final int i, final List<ApplyWayBean.BankCardBean> mItemDataList) {

        MyViewHolder myViewHolder = (MyViewHolder) viewHolder;
        if (isShow) {
            myViewHolder.llRemove.setVisibility(View.VISIBLE);
        } else {
            myViewHolder.llRemove.setVisibility(View.GONE);
        }
        String bb = mItemDataList.get(i).getAccount().substring(mItemDataList.get(i).getAccount().length()-4,mItemDataList.get(i).getAccount().length());
        myViewHolder.tvAccount.setText("**** **** **** "+bb);
        myViewHolder.tvName.setText("尾号 "+bb+" 储蓄卡");
        myViewHolder.llRemove.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setDialog(i,mItemDataList.get(i).getWayId());
            }
        });
    }

    @Override
    public int getListLayoutId() {
        return R.layout.item_union_pay;
    }

    @Override
    public RecyclerView.ViewHolder createViewHolder(View view) {
        return new MyViewHolder(view);
    }

    class MyViewHolder extends BaseRecyclerViewHolder {
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_account)
        TextView tvAccount;
        @BindView(R.id.ll_remove)
        LinearLayout llRemove;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public void setShow(boolean isShow) {
        this.isShow = isShow;
        notifyDataSetChanged();
    }
    public void setDialog(final int index, final String wayId){
        new AlertDialog(mContext).builder().setTitle("确定删除银行卡？")
                .setPositiveButton("取消", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                }).setNegativeButton("确定", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                presenter.deleteApplyWay(index,wayId);
            }
        }).show();
    }
}
